package com.timous.链表;

/**
 * https://leetcode-cn.com/problems/remove-linked-list-elements/
 * @author Timous
 * @create 2020-12-22 15:34
 **/
public class _203_移除链表元素 {
    public ListNode removeElements(ListNode head, int val) {
        if (head == null || head.next == null){
            if (head.val == val){
                head = null;
            }
            return head;
        }
        ListNode node  = head;
        while (node.next != null){
            if (node.next.val == val){
                node.next = node.next.next;
            }
            node = node.next;
        }
        return head;
    }
}
